<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
<script>
  //1、使用setTimeout
  // setTimeout(()=> {
  //   console.log('hello world!');
  // }, 1000)

  //2、使用Promise，参数要求传入一个函数，这个函数要求传入两个参数resolve和reject，resolve和reject本身也是函数.
  //  网络请求都在Promise里面，处理网络请求的代码都在Promise后的then里面
  new Promise((resolve, reject) => {

    // 第一次网络请求的代码
    setTimeout(() => {
      resolve()
    }, 1000);
  }).then(() => {

    // 第一次拿到结果的处理代码
    console.log('this is the first time.');
    console.log('this is the first time.');

    return new Promise((resolve, reject) => {

      //第二次网络请求的代码
      setTimeout(() => {
        resolve()
      }, 1000);
    })
  }).then(() => {

    //第二次拿到结果的处理代码
    console.log('this is the second time.');
    console.log('this is the second time.');
    
    return new Promise((resolve, reject) => {

      //第三次网路请求的代码
      setTimeout(() => {
        resolve()
      }, 1000);
    })
  }).then(() => {

    //第三次处理的代码
    console.log('this is the third time');
    console.log('this is the third time');
  })
</script>
</body>
</html>